package com.team9.fitness.mapper;

import com.team9.fitness.entity.ExerciseInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 运动信息映射器
 */
@Mapper
public interface ExerciseInfoMapper {

    @Insert("INSERT INTO exercise_info (name, category, description, has_speed, has_heart_rate, created_at, updated_at) "
            +
            "VALUES (#{name}, #{category}, #{description}, #{hasSpeed}, #{hasHeartRate}, NOW(), NOW())")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(ExerciseInfo exerciseInfo);

    @Select("SELECT * FROM exercise_info WHERE id = #{id}")
    ExerciseInfo selectById(Long id);

    @Select("SELECT * FROM exercise_info ORDER BY name")
    List<ExerciseInfo> selectAll();

    @Select("SELECT * FROM exercise_info WHERE category = #{category} ORDER BY name")
    List<ExerciseInfo> selectByCategory(String category);

    @Select("SELECT * FROM exercise_info WHERE name LIKE CONCAT('%', #{keyword}, '%') ORDER BY name")
    List<ExerciseInfo> searchByName(String keyword);

    @Select("SELECT DISTINCT category FROM exercise_info ORDER BY category")
    List<String> selectAllCategories();

    @Update("UPDATE exercise_info SET name = #{name}, category = #{category}, description = #{description}, " +
            "has_speed = #{hasSpeed}, has_heart_rate = #{hasHeartRate}, updated_at = NOW() WHERE id = #{id}")
    int update(ExerciseInfo exerciseInfo);

    @Delete("DELETE FROM exercise_info WHERE id = #{id}")
    int deleteById(Long id);
}




